package Vue;

import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Dimension;
import javax.swing.JComboBox;
import javax.swing.JButton;

import Controleur.LoadSource;
import Controleur.LouerVeloBtnListener;
import Controleur.LouerVeloComboListener;
import java.awt.Color;
import java.util.ArrayList;
import java.awt.Point;

/**
 * Définit la fenêtre de location d'un vélo
 */
public class LouerVelo extends JDialog {

	
	private static final long serialVersionUID = 1L;
	/** Liste déroulante des clients */
	JComboBox comboBoxClient;
	/** Bouton validant la location d'un vélo */
	JButton btnValider = new JButton("Valider");
	/** Liste déroulante des stations */
	JComboBox comboBoxStation;
	/** Label indiquant que le client a déja une location en cours */
	JLabel lblClientLoueAct = new JLabel("Le client loue actuellement un v\u00E9lo.");
	/** Label indiquant que a station est vide et que la location est donc impossible */
	private final JLabel lblLaStationEst = new JLabel("La station est vide.");
	
	/**
	 * Instancie la fenetre de location de vélo
	 */
	public LouerVelo() {
		setModal(true);
		setLocation(new Point(200, 200));
		setMinimumSize(new Dimension(466, 300));
		setResizable(false);

		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);

		JLabel lblLouerUnVlo = new JLabel("Louer un v\u00E9lo");
		lblLouerUnVlo.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblLouerUnVlo.setBounds(164, 11, 110, 25);
		panel.add(lblLouerUnVlo);

		JLabel lblClient = new JLabel("Client");
		lblClient.setBounds(67, 67, 46, 14);
		panel.add(lblClient);

		JLabel lblStation = new JLabel("Station");
		lblStation.setBounds(67, 131, 46, 14);
		panel.add(lblStation);

		
		ArrayList<Object> clients = LoadSource.getClients();
		comboBoxClient = new JComboBox(clients.toArray());
		comboBoxClient.addActionListener(new LouerVeloComboListener(this));

		comboBoxClient.setBounds(123, 64, 100, 20);
		panel.add(comboBoxClient);


		ArrayList<Object> stations = LoadSource.getStations();
		comboBoxStation = new JComboBox(stations.toArray());
		comboBoxStation.setBounds(123, 128, 100, 20);
		panel.add(comboBoxStation);
		comboBoxStation.addActionListener(new LouerVeloComboListener(this));

		btnValider.setEnabled(false);
		btnValider.setForeground(new Color(0, 128, 0));
		btnValider.setFont(new Font("Tahoma", Font.BOLD, 12));

		btnValider.addActionListener(new LouerVeloBtnListener(this));

		btnValider.setBounds(185, 221, 89, 23);
		panel.add(btnValider);

		lblClientLoueAct.setBounds(111, 174, 232, 14);
		panel.add(lblClientLoueAct);
		lblLaStationEst.setBounds(111, 199, 163, 14);

		panel.add(lblLaStationEst);

		// On selectionne la première ligne
		if (comboBoxClient.getItemCount() != 0)
			comboBoxClient.setSelectedIndex(0);

		// On selectionne la première ligne
		if (comboBoxStation.getItemCount() != 0)
			comboBoxStation.setSelectedIndex(0);
	}

	
	// GETTERS
	/**
	 * Getter liste des clients
	 * @return la ComboBoxClient
	 */
	public JComboBox getComboBoxClient() {
		return comboBoxClient;
	}
	/**
	 * Getter btnValider
	 * @return le Bouton Valider
	 */
	public JButton getBtnValider() {
		return btnValider;
	}
	/**
	 * Getter liste des stations
	 * @return la ComboBoxStation
	 */
	public JComboBox getComboBoxStation() {
		return comboBoxStation;
	}
	/**
	 * Getter label LoueActuellement
	 * @return le label LblClientLoueAct
	 */
	public JLabel getLblClientLoueAct() {
		return lblClientLoueAct;
	}
	
	/**
	 * Getter label La Station Est Vide
	 * @return le label LblLaStationEst
	 */
	public JLabel getLblLaStationEst() {
		return lblLaStationEst;
	}
	/**
	 * Méthode fermant la fenêtre
	 */
	public void close() {
		this.dispose();
	}

}
